package com.zhku.goods.controller;

import com.zhku.base.model.PageParams;
import com.zhku.base.model.PageResult;
import com.zhku.base.model.RestResponse;
import com.zhku.goods.model.dto.EvaluateDto;
import com.zhku.goods.model.dto.ReturnEvaluateDto;
import com.zhku.goods.model.po.TtGoodsEvaluate;
import com.zhku.goods.service.TtGoodsEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(value = "商品评价相关接口", tags = "商品评价相关接口")
@RestController
public class TtGoodsEvaluateController {

    @Autowired
    private TtGoodsEvaluateService ttGoodsEvaluateService;

    @ApiOperation("新增商品评价接口")
    @PostMapping("/createEvaluate")
    public RestResponse<TtGoodsEvaluate> createEvaluate(@RequestBody EvaluateDto evaluateDto) {
        TtGoodsEvaluate ttGoodsEvaluate = ttGoodsEvaluateService.createEvaluate(evaluateDto);
        return RestResponse.success(ttGoodsEvaluate);
    }

    @ApiOperation("删除商品评价接口")
    @PostMapping("/deleteEvaluate/{id}")
    public RestResponse deleteEvaluate(@PathVariable("id") String id) {
        ttGoodsEvaluateService.deleteEvaluate(id);
        return RestResponse.success();
    }

    @ApiOperation("查看当前商品有哪些评价")
    @PostMapping("/getEvaluateList/{id}")
    public PageResult<ReturnEvaluateDto> list(PageParams pageParams, @PathVariable("id") String id) {
        PageResult<ReturnEvaluateDto> evaluateList = ttGoodsEvaluateService.getEvaluateList(pageParams, id);
        return evaluateList;
    }
}
